package no.uis.archiva.consumer.liferay;


public class LiferayLicense {

  private enum License {
    CC_ATTRIBUTION_SHARE_ALIKE_3_0_NORWAY(
      "Create Commons Attribution-Share Alike 3.0 Norway",
      true,
      "http://creativecommons.org/licenses/by-nc/3.0/no/"
    ),
    CC_ATTRIBUTION_3_0_NORWAY(
      "Creative Commons Attribution 3.0 Norway",
      true,
      "http://creativecommons.org/licenses/by/3.0/no/"
    ),
    CC_ATTRIBUTION_NC_3_0_NORWAY(
      "Creative Commons Attribution-Noncommercial 3.0 Norway",
      true,
      "http://creativecommons.org/licenses/by-nc/3.0/no/"
    ),
    CC_ATTRIBUTION_NC_ND_3_0_NORWAY(
      "Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Norway",
      true,
      "http://creativecommons.org/licenses/by-nc-nd/3.0/no/"
    ),
    CC_ATTRIBUTION_NC_SA_3_0_NORWAY(
      "Creative Commons Attribution-Noncommercial-Share Alike 3.0 Norway",
      true,
      "http://creativecommons.org/licenses/by-nc-sa/3.0/no/"
    ),
    CC_ATTRIBUTION_ND_3_0_NORWAY(
      "Creative Commons Attribution-No Derivative Works 3.0 Norway",
      true,
      "http://creativecommons.org/licenses/by-nd/3.0/no/"
    ),
    MIT(
      "MIT",
      true,
      "http://www.opensource.org/licenses/mit-license.php"
    ),
    GPL_3(
      "GPL v3",
      true,
      "http://www.gnu.org/licenses/gpl-3.0.txt"
    ),
    APACHE_2_0(
      "Apache License",
      true,
      "http://www.apache.org/licenses/LICENSE-2.0.txt"
    );
    
    private LiferayLicense license;

    private License(String name, boolean approved, String url) {
      this.license = new LiferayLicense(name, approved, url);
    }
    
    public LiferayLicense getLicense() {
      return license;
    }
  }

  private String name;
  private boolean osiApproved;
  private String url;
  
  private LiferayLicense(String licenseName, boolean approved, String url) {
    this.name = licenseName;
    this.osiApproved = approved;
    this.url = url;
  }

  public static LiferayLicense buildLicense(String licenseName) {
    for (License license : License.values()) {
      if (license.getLicense().getName().equals(licenseName)) {
        return license.getLicense();
      }
    }
    return License.CC_ATTRIBUTION_SHARE_ALIKE_3_0_NORWAY.getLicense();
  }

  public String getName() {
    return name;
  }

  public boolean isOsiApproved() {
    return osiApproved;
  }

  public String getUrl() {
    return url;
  }
}
